package com.renne.email.controller;

import java.util.List;

import cn.hutool.core.util.DesensitizedUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.renne.common.core.controller.BaseController;
import com.renne.common.core.domain.AjaxResult;
import com.renne.common.core.page.TableDataInfo;
import com.renne.common.annotation.Log;
import com.renne.common.enums.BusinessType;

import com.renne.email.domain.MailSenderConfigQuery;
import com.renne.email.domain.MailSenderConfigVo;
import com.renne.email.service.IMailSenderConfigService;


/**
 * 发件人邮箱配置Controller
 *
 * @author LiuYu
 * @date 2024-07-26
 */
@Tag(name = "mail-sender-config-controller", description = "发件人邮箱配置")
@RestController
@RequestMapping("/email/sender/config")
public class MailSenderConfigController extends BaseController {

    @Autowired
    private IMailSenderConfigService mailSenderConfigService;


    /**
     * 查询发件人邮箱配置列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询发件人邮箱配置列表")
    public TableDataInfo list(MailSenderConfigQuery query) {
        startPage();
        List<MailSenderConfigVo> list = mailSenderConfigService.getMailSenderConfigVoList(query);
        list.forEach(item -> item.setAuthorizationCode(DesensitizedUtil.desensitized(item.getAuthorizationCode(), DesensitizedUtil.DesensitizedType.PASSWORD)));
        return getDataTable(list);
    }

    /**
     * 获取发件人邮箱配置详细信息
     */
    @GetMapping("/{senderEmailConfigId}")
    @Operation(summary = "查询发件人邮箱配置详细")
    public AjaxResult getById(@Parameter(description = "主键ID") @PathVariable("senderEmailConfigId") String senderEmailConfigId) {
        return success(mailSenderConfigService.getMailSenderConfigVoById(senderEmailConfigId));
    }

    /**
     * 新增发件人邮箱配置
     */
    @PostMapping
    @Log(title = "发件人邮箱配置", businessType = BusinessType.INSERT)
    @Operation(summary = "新增发件人邮箱配置")
    public AjaxResult add(@RequestBody MailSenderConfigVo mailSenderConfigVo) {
        return toAjax(mailSenderConfigService.saveMailSenderConfigVo(mailSenderConfigVo));
    }

    /**
     * 修改发件人邮箱配置
     */
    @PutMapping
    @Log(title = "发件人邮箱配置", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改发件人邮箱配置")
    public AjaxResult update(@RequestBody MailSenderConfigVo mailSenderConfigVo) {
        return toAjax(mailSenderConfigService.updateMailSenderConfigVo(mailSenderConfigVo));
    }

    /**
     * 删除发件人邮箱配置记录
     */
    @DeleteMapping("/{senderEmailConfigId}")
    @Log(title = "发件人邮箱配置", businessType = BusinessType.DELETE)
    @Operation(summary = "删除发件人邮箱配置")
    public AjaxResult delete(@Parameter(description = "主键ID") @PathVariable("senderEmailConfigId") String senderEmailConfigId) {
        return toAjax(mailSenderConfigService.deleteMailSenderConfigByIds(senderEmailConfigId));
    }
}
